package book.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import book.entity.Book;
import book.service.BookService;
import book.service.impl.BookServiceImpl;

/**
 * Servlet implementation class BookUpdateServlet
 */
public class BookUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	
	BookService bookService = new BookServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		doPost(request, response);
		
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		String bookId = request.getParameter("bookId");
		String bookName = request.getParameter("bookName");
		String authorName = request.getParameter("authorName");
		String price = request.getParameter("price");
		String categoryId = request.getParameter("categoryId");
		
		Book book = new Book();
		
		book.setBookId(Integer.parseInt(bookId));
		book.setBookName(bookName);
		book.setAuthorName(authorName);
		book.setPrice(Double.parseDouble(price));
		book.setCategoryId(Integer.parseInt(categoryId));
		
		
		System.out.println(book);
		
		
		
		try {
			
			
			bookService.updataBook(book);
			
			response.sendRedirect("BookgetListServlet");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}

}
